import static org.junit.Assert.*;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import org.junit.Test;

public class deadlock_test {
  @Test(timeout = 1000)
  public void test() {
    deadlock.lock();
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }

    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    long[] deadlockedThreads = bean.findDeadlockedThreads();

    assertTrue("detected deadlock", deadlockedThreads.length == 0);
  }
}
